package com.bupt.clusterlistener.config;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

@Configuration
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ClusterIP {
    private HashMap<String, String> ipMap = new HashMap<String, String>();

    @Value("${k8snode1}")
    private String node1;

    @Value("${k8snode2}")
    private String node2;

    @Value("${k8snode3}")
    private String node3;

    public void setNode1(String node1) {
        this.node1 = node1;
        ipMap.put("k8snode1", node1);
    }

    public void setNode2(String node2) {
        this.node2 = node2;
        ipMap.put("k8snode2", node2);
    }

    public void setNode3(String node3) {
        this.node3 = node3;
        ipMap.put("k8snode3", node3);
    }

    public String getIp(String key) {
        if (ipMap.isEmpty()) {
            ipMap.put("k8snode1", node1);
            ipMap.put("k8snode2", node2);
            ipMap.put("k8snode3", node3);
        }
        return ipMap.get(key);
    }
}
